


<template>

    <el-form ref="ruleFormRef" style="max-width: 600px" :model="form" :rules="rules" label-width="auto"
        class="demo-ruleForm" :size="formSize" status-icon>


        <el-form-item label="部门">
            <el-select v-model="form.departId" placeholder="请选择" style="width: 180px;" clearable
                @change="PositionList2()">
                <el-option v-for="item in departs" :key="item.departId" :label="item.departName" :value=item.departId />
            </el-select>
        </el-form-item>


        <el-form-item label="职位">
            <el-select v-model="form.positionId" style="width: 180px;" placeholder="请选择" clearable>
                <el-option v-for="item in positions2" :key="item.positionId" :label="item.positionName"
                    :value="item.positionId" />
            </el-select>
        </el-form-item>


        <el-form-item label="员工姓名" prop="employName">
            <el-input v-model="form.employName" />
        </el-form-item>

        <el-form-item label="上级负责人">
            <el-select v-model="form.responsiblePerson" placeholder="请选择" clearable style="width: 180px;">
                <el-option label="孟盘龙" :value="1" />
                <el-option label="刘永刚" :value="2" />
                <el-option label="赵思彤" :value="3" />
                <el-option label="牛骞若" :value="4" />
                <el-option label="赵秋实" :value="5" />
                <el-option label="于晋哲" :value="6" />
            </el-select>
        </el-form-item>


        <el-form-item label="入职日期">
            <el-date-picker v-model="form.entryDate" type="date" placeholder="入职日期" style="width: 100%" />
        </el-form-item>

        <el-form-item label="申请日期">
            <el-date-picker v-model="form.applyDate" type="date" placeholder="入职日期" style="width: 100%" />
        </el-form-item>



        <el-form-item label="试用期工作总结" prop="summarize">
            <el-input v-model="form.summarize" />
        </el-form-item>

        <el-form-item label="对公司的意见和建议" prop="opinion">
            <el-input v-model="form.opinion" />
        </el-form-item>

        <el-form-item>

            <el-button type="success" @click="submitForm(ruleFormRef,1)">提交审核</el-button>

            <el-button type="danger" @click="resetForm(ruleFormRef)">清空</el-button>

        </el-form-item>



    </el-form>



</template>

<script setup lang="ts">


import { ElMessage, ElMessageBox } from 'element-plus'
import { ref, reactive, onMounted } from 'vue';
import { useRoute } from 'vue-router';
import axios from '@/api/http';
const route=useRoute()
import type { ComponentSize, FormInstance, FormRules } from 'element-plus'
const formSize = ref<ComponentSize>('default')
const ruleFormRef = ref<FormInstance>()
const rules = reactive<FormRules>({
    employName: [
        { required: true, message: '员工姓名不为空', trigger: 'blur' },
    ],
})


const form = reactive({
    promotionId:"",
    departId: "",
    positionId: "",
    employName: "",
    responsiblePerson: "",
    entryDate: "",
    applyDate: "",
    summarize: "",
    opinion: "",
    "approvalStatus": 1,
    "approvalPerson": "",
    "isDelete": 0,
    "createName": "",
    "createTime": "2024-08-29",
    "updateName": "",
    "updateTime": "2024-08-29"

})

const Fan = () => {
    axios.get('/api/promotion/Fanpromotion?promotionId=' + route.query.promotionId)
        .then(function (res) {
            console.log(res);
            form.promotionId = res.promotionId
            form.applyDate=res.applyDate
            form.entryDate=res.entryDate
            form.employName = res.employName
            form.positionId=res.positionId      
            form.departId=res.departId
            form.responsiblePerson=res.responsiblePerson
            form.summarize=res.summarize
            form.opinion = res.opinion
            form.approvalStatus = res.approvalStatus
            form.approvalPerson = res.approvalPerson
            form.isDelete = res.isDelete
            form.createName = res.createName
            form.createTime = res.createTime
            form.updateName = res.updateName
            form.updateTime = res.updateTime
            console.log(form)
        })
        .catch(function (error) {
            console.log(error);
        
    })
     

}


onMounted(() => {
    DepartList()
    Fan()
    console.log(form)
    console.log(route.query.promotionId)
})


const departs = ref([])
const DepartList = () => {

    axios.get('/api/promotion/GetDepartMentList')
        .then(function (res) {
            departs.value = res
            console.log(res)
        })
        .catch(function (error) {
            console.log(error);
        })

}


const positions2 = ref([])
const PositionList2 = () => {
    positions2.value = []
    axios.get('/api/promotion/GetPositionList?departId=' + form.departId + '')
        .then(function (res) {
            positions2.value = res
            console.log(res)
        })
        .catch(function (error) {
            console.log(error);
        })

}





const submitForm = async (formEl: FormInstance | undefined, type: number) => {
    if (!formEl) return
    await formEl.validate((valid, fields) => {
        if (valid) {        
            axios.post('/api/promotion/Sendpromotion?type=' + type, form)
                .then(function (res) {
                    if (res > 0) {
                        console.log(form)
                        ElMessage.success('提交成功')

                    }
                    else {
                        ElMessage.error('提交失败')
                    }



                })


        } else {
            console.log('error submit!', fields)
        }
    })
}

const resetForm = (formEl: FormInstance | undefined) => {
    if (!formEl) return
    formEl.resetFields()
}





</script>







